<?php
/**
 * @version $Id: Character.php 174 2008-02-24 15:56:02Z mikhail.miguel $
 */

require_once dirname(dirname(dirname(dirname(__FILE__)))).'/lib/trackback/spamcheck.php';

class SpamCheck_Character extends SpamCheck {
    var $_options = array(
        'sources'       => array(
            '((?:\xA4[\xA1-\xF3])+|(?:\xA5[\xA1-\xF6])+|(?:[\xB0-\xF4][\x00-\xFF])+)'
        ),
        'elements'      => array(
            'title',
            'excerpt',
            'blog_name'
         ),
        'minlength'    => 1,
//        'minmatches' => 1
    );
    
    function SpamCheck_Character($options=null) {
        if (is_array($options)) {
            foreach ($options as $key => $val) {
                $this->_options[$key] = $val;
            }
        }
    }

    function _checkSource(&$source, $trackback)
    {
        $matched = '';
        foreach ($this->_options['elements'] as $element) {
            if(TrackbackService::isError($item = $trackback->get($element))) {
            	return TrackbackService::setError($item->getMessage().'<br />'.' Cannot procede without it.');
            }
            $elements[$element] = $item;
        }
        foreach ($elements as $element) {
            if (preg_match_all('/'. $source. '/x', $element, $matches)) {
                $matched .= join("", $matches[1]);
            }
        }
        if(mb_strlen($matched) < $this->_options['minlength']) {
            return TrackbackService::setError('Our language characters are not found in your comment.');
        }
        return true;
    }
    
}    
?>